
/**
*
* @ Author: YL
* @ Data: 2020-09-10 14:16
*/
export default class PackageMgr {

    constructor() {

    }

    private static _instance: PackageMgr;
    public static get Instance(): PackageMgr {
        if (PackageMgr._instance == null) {
            PackageMgr._instance = new PackageMgr();
        }
        return PackageMgr._instance;
    }

    /**
     * 
     * @param packageName 包名
     * @param scope 作用域
     * @param callBack1 加载成功回调
     * @param callBack2 加载失败回调
     */
    public loadPackage(packageName: string, scope:any, callBack1?:Function, callBack2?:Function): void {
        if (typeof wx != "undefined") {
            wx.loadSubpackage({
                name: packageName,
                success: function () {
                    if(!callBack1) return;
                    callBack1.call(scope);
                },
                fail: function () {
                    if(!callBack2) return;
                    callBack2.call(scope);
                }
            })
        }
    }
}